<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
          integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

    <title>进销存管理系统</title>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script crossorigin="anonymous" integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT"
            src="https://lib.baomitu.com/jquery/3.3.1/jquery.min.js"></script>

    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
            integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
            crossorigin="anonymous"></script>
    <script crossorigin="anonymous" integrity="sha384-Ysr53n0PIGi7rAduJ+BAMGbxA9RFQwIQfPh2bD9pf1x3vrnDsdX4SlwCNpxmrPIi"
            src="https://lib.baomitu.com/layer/3.1.1/layer.js"></script>


</head>
<body>


<script>
    function ajaxPost() {
        var name = $("#subName").val();
        var num = $("#subNum").val();
        var firm = $("#subFirm").val();
        var sort = $("#subSort").val();
        var price = $("#subPrice").val();
        if (name == '') {
            layer.msg('请输入型号');
            return false;
        }
        if (num == '') {
            layer.msg('请输入库存');
            return false;
        }
        if (firm == '') {
            layer.msg('请输入厂商');
            return false;
        }
        if (sort == '') {
            layer.msg('请输入分类');
            return false;
        }
        if (price == '') {
            layer.msg('请输入价格');
            return false;
        }

        var formData = $("#myform").serialize();
        $.ajax({
            type: "post",
            url: "{:url('index/changeFun')}",
            data: formData,//data传递过去
            success: function (data) {
                // alert(data);
                if (data !== 0) {
                    layer.msg('修改成功', {
                        icon: 16
                        , shade: 0.01
                    });

                    function jump() {
                        window.location.href = "{:url('index/mian')}";
                    }
                    setTimeout(jump, 1000);
                } else{
                    layer.msg('未修改数据，请重试');
                }
            }
        });
    }
</script>

<script>
    function ajaxDel() {
        layer.confirm('您确定删除此型号以及库存？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            var formData = $("#myform").serialize();
            $.ajax({
                type: "post",
                url: "{:url('index/del')}",
                data: formData,//data传递过去
                success: function (data) {
                    // alert(data);
                    if (data == 1) {
                        layer.msg('删除成功', {
                            icon: 16
                            , shade: 0.01
                        });

                        function jump() {
                            window.location.href = "{:url('index/mian')}";
                        }
                        setTimeout(jump, 1000);
                    } else{
                        layer.msg('删除失败，请重试');
                    }
                }
            });
        }, function(){
            layer.msg('未改动数据');
        });
    }
</script>



<div class="container">
    <div class="row">
        <div class="col-md-4">
            <br>
        </div>
        <div class="col-md-4">
            <div class="m-4">
                <br><br><br>
                <form id="myform" class="form-signin">
                    <h2 class="form-signin-heading">进销存管理系统</h2>
                    <br>
                    <h4>修改库存</h4>
                    <h6 class="text-danger">注意：销售的产品库存请不要在此修改，不然不会计入销售统计</h6>

                    <div class="input-group mb-3">
                        <div class="input-group-prepend">
                            <span class="input-group-text" id="name">型号</span>
                        </div>
                        <input type="text" class="form-control" name="name" id="subName" value="{$list.name}"
                               aria-label="Username"
                               aria-describedby="basic-addon1" readonly>
                    </div>

                    <div class="input-group mb-3">
                        <div class="input-group-prepend">
                            <span class="input-group-text" id="num">库存</span>
                        </div>
                        <input type="text" class="form-control" name="num" id="subNum" value="{$list.num}"
                               aria-label="Username"
                               aria-describedby="basic-addon1">
                    </div>

                    <div class="input-group mb-3">
                        <div class="input-group-prepend">
                            <span class="input-group-text" id="firm">厂商</span>
                        </div>
                        <input type="text" class="form-control" name="firm" id="subFirm" value="{$list.firm}"
                               aria-label="Username"
                               aria-describedby="basic-addon1">
                    </div>

                    <div class="input-group mb-3">
                        <div class="input-group-prepend">
                            <span class="input-group-text" id="sort">分类</span>
                        </div>
                        <input type="text" class="form-control" name="sort" id="subSort" value="{$list.sort}"
                               aria-label="Username"
                               aria-describedby="basic-addon1">
                    </div>

                    <div class="input-group mb-3">
                        <div class="input-group-prepend">
                            <span class="input-group-text" id="price">价格</span>
                        </div>
                        <input type="text" class="form-control" name="price" id="subPrice" value="{$list.price}"
                               aria-label="Username"
                               aria-describedby="basic-addon1">
                    </div>


                    <button class="btn btn-lg btn-primary btn-block" type="button" onclick="ajaxPost()">修改</button>
                    <button class="btn btn-lg btn-danger btn-block" type="button" onclick="ajaxDel()">删除</button>

                </form>
                <a class="text-muted " href="{:url('index/mian')}">
                    <button class="btn btn-lg btn-danger btn-block mt-2" type="submit">首页</button>
                </a>

            </div>
        </div>
        <div class="col-md-4">
            <br>
        </div>
    </div>
</div>


<!--<form id="myform">-->
<!--    &lt;!&ndash;这里给表单起个id用于获取表单并序列化&ndash;&gt;-->
<!--    <input type="text" name="account"/>-->
<!--    <input type="password" name="passwd"/>-->
<!--    <button type="button" onclick="ajaxPost()">-&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;</button>-->
<!--</form>-->
<!--<div id="content">-->
<!--</div>-->


</body>
</html>